package com.demo.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundGeoOperations;
import org.springframework.data.redis.core.RedisTemplate;

public class RedisUtil {
    public static String getId(String type, RedisTemplate<String,String> redisTemplate){
        String key = type + "_id";
        String typeId = "";
        if (!redisTemplate.hasKey(key)){
            if ("menu".equals(type)){
                redisTemplate.boundValueOps(key).set("100");
                typeId = "100";
            }else {
                redisTemplate.boundValueOps(key).set("1000000");
                typeId = "1000000";
            }
        }else {
            Long increment = redisTemplate.boundValueOps(key).increment(1);
            typeId = String.valueOf(increment);
        }
        return typeId;
    }
}
